#ifndef prs_FrmDate_H
#define prs_FrmDate_H

#include "prs_FrmControl.h"
#include "prs_FrmUseTemplate.h"
#include "prs_FrmDateStyle.h"
#include "frm_control_TDate.h"

namespace prs {

///////////////////////////////////////////////////////////////////////////////
struct TNodeFrmDate;
///////////////////////////////////////////////////////////////////////////////

struct TNodeFrmDateControl : public frm::control::TDate
{
  TNodeFrmDateControl(
    frm::control::TWindow &Window,
    TNodeFrmDate &Node
  ):TDate(Window),node(Node) {}
  //
  virtual bool UpdateValue(svl::TDateTime V);
  
private:  
  TNodeFrmDate &node;
};

///////////////////////////////////////////////////////////////////////////////

struct TNodeFrmDate : public TNodeFrmControl
{
  DECLARE_ClientNode()
  //
  typedef TNodeFrmDateStyle   TStyle;
  typedef TNodeFrmDateControl TControl;
  //
  TAttrNodeType<nodeType_Date> NodeType;
  TAttrBindPropDateTime<attrName_Value,TNodeUseTemplateParam*> Value;
  TAttrPointerNoCopy<attrName_Control,TNodeFrmDateControl*> Control;
  //
  TNodeFrmDate():NodeType(this),Value(this),Control(this) {}
 ~TNodeFrmDate() { delete Control.GetValue(); }
  
  TNodeFrmDateControl *BuildControl(
    frm::control::TPanel *ParentControl
  );
private:
  virtual void             TNode_SetPropDateTimeValue(TAttrDateTimeBase &Attr,svl::TDateTime &V);
  virtual svl::TDateTime  &TNode_GetPropDateTimeValue(TAttrDateTimeBase &Attr);
  void updateValueInControl();
  //
  svl::TDateTime value;
  svl::TLocksStack::TState St;
  svl_Except;
};

///////////////////////////////////////////////////////////////////////////////

struct TRuleFrmDate : public snt::TRule
{
  TRuleFrmDate(
    snt::text::TContext &Context,
    svl::TVariant &VParentNode,
    TRuleFrmChildrenBase &RFrmChildren,
    TRuleSetNodeIdOptionally &RSetNodeIdOptionally,
    TRuleSetAttrValue &RSetAttrValue,
    TRuleSetStyle &RStyle
  );

private:  
  bool FSetParam(TRuleSetAttrValue::TFuncValueIdentParams &Params) {
    return TNodeDefTemplate::AddLinkAttrByParamId(Params.Attr,TFrmDateTimeValue(),Params.Ident,Params.OutError);
  }
  //
  svl::TVariant &vParentNode;
  snt::TAlter AAttr1;
  snt::TRule  RAttr1,RAttr;

  svl_Except;
};

///////////////////////////////////////////////////////////////////////////////
}

#endif
